/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package vue;

import java.awt.Color;
import java.awt.Font;
import java.awt.FontFormatException;
import java.io.IOException;
import java.io.InputStream;
import javax.swing.Icon;
import javax.swing.JButton;
import utiles.FourmizLogger;

/**
 *
 * @author S219
 */
public class FourmizJButton extends JButton {

    public FourmizJButton(char icone)
    {
        this(String.valueOf(icone));
    }
    
    public FourmizJButton(String texte)
    {
        this(texte, null);
    }
    
    public FourmizJButton(Icon icon)
    {
        this(null, icon);
    }
    
    public FourmizJButton(String texte, Icon icon) {
        super(texte,icon);

        String path = "/fonts/fontawesome-webfont.ttf";
        try {
            InputStream in = this.getClass().getResourceAsStream(path); // Chargement de la police a partir de src/
            Font ttfBase = Font.createFont(Font.TRUETYPE_FONT, in);
            Font ttfReal = ttfBase.deriveFont(Font.PLAIN, 24);
            this.setFont(ttfReal);
            in.close(); //Merci d'éviter de me faire perdre 1h à cause de cet oubli
        } catch (FontFormatException | IOException e) {
            FourmizLogger.debug(e, "La police "+ path +" est introuvable");
        }
        this.setOpaque(false);
        this.setContentAreaFilled(true);
        this.setBorderPainted(true);
    }
    
    public void agrandir(int pourcents)
    {
        Font ttfReal = this.getFont();
        
        int actual_size = ttfReal.getSize();
        int new_size = actual_size + ((pourcents * actual_size) / 100);
        Font ttf = ttfReal.deriveFont(Font.PLAIN, new_size);
        
        this.setFont(ttf);
    }
    
    public void reduire(int pourcents)
    {
        this.agrandir(pourcents * -1);
    }
}
